import React, { Component } from 'react';
import {
    StyleSheet,
    Text,
    View,
    TouchableOpacity, ToastAndroid
} from 'react-native';
import MyNav from "../extendsComponent/MyNav";
export default class ItemDetail extends Component {
    //接收上一个页面传过来的title显示出来
    // static navigationOptions = ({ navigation }) => ({
    //     title: navigation.state.params.title,
    // });

    // 点击返回上一页方法
    backVC=()=>{
        //返回首页方法
        this.props.navigation.goBack();
    }
    leftbutton=()=>{
        //返回首页方法
        this.props.navigation.goBack();
    }
    rightbutton=()=>{
        ToastAndroid.show("显示分享平台",ToastAndroid.SHORT);
    }
    componentDidMount(){
        const {setParams} = this.props.navigation;
        setParams({title:"我是新的title"});
    }
    render() {
        const { state,setParams} = this.props.navigation;
        return (
            <View style={styles.container}>
                <MyNav
                    title={state.params.title}
                    color={"#1aa1e5"}
                    textColor={"white"}
                    leftIconWidth={20}
                    leftIconHeight={20}
                    leftIcon={require('../res/arrow.png')}
                    leftbutton={this.leftbutton.bind(this)}
                    rightBtnTitle={"分享"}
                    rightBtnTitleColor={"white"}
                    stateType={'1'}
                    rightbutton={this.rightbutton.bind(this)}
                />
                <TouchableOpacity style={{
                    height:40,
                    backgroundColor:'green',
                    justifyContent: 'center'}}
                                  onPress={() =>{this.backVC()}}>
                    <Text>{state.params.des}</Text>
                </TouchableOpacity>
                <TouchableOpacity style={{
                    height:40,
                    backgroundColor:'blue',
                    justifyContent: 'center'}}
                                  onPress={() =>setParams({title:"我是新的title1"})}>
                    <Text>点击setParams</Text>
                </TouchableOpacity>
            </View>
        );
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: '#F5FCFF',
    },
});
